<template>
  <el-dialog :visible.sync="dialogFormVisible" width="60%" ref="dialog" :append-to-body="true"
    :close-on-click-modal="false" center>
    <template slot="title">
      <span class="add-main-tital">
        <h4>新增物资</h4>
      </span>
    </template>
    <div class="add-container">
      <div class="add-main">
        <div class="search-group">
          <div class="search-gropu-item">
            <label>物资名称</label>
            <el-input v-model="listQuery.wuzimc"></el-input>
          </div>
          <div class="search-button">
            <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetlist">重置</el-button>
          </div>
        </div>

        <div class="table-list">
          <el-table v-loading="listLoading" :data="ruleForm.rows" :element-loading-text="elementLoadingText"
            @selection-change="setSelectRows" highlight-current-row height="100%" :header-cell-style="{
              'border-bottom': '1px solid #cbcccd',
              'border-top': '1px solid #cbcccd',
            }">
            <el-table-column show-overflow-tooltip type="selection"></el-table-column>
            <el-table-column show-overflow-tooltip label="序号" width="55">
              <template #default="scope">
                {{ scope.$index + listQuery.pageSize * (listQuery.pageIndex - 1) + 1 }}

              </template>
            </el-table-column>
            <!-- <el-table-column show-overflow-tooltip prop="wuzibm" label="物资代码"></el-table-column> -->
            <el-table-column show-overflow-tooltip prop="wuzimc" label="物资名称"></el-table-column>
            <el-table-column show-overflow-tooltip prop="guigexh" label="规格型号"></el-table-column>
            <el-table-column show-overflow-tooltip prop="jiliangdw" label="计量单位"></el-table-column>
          </el-table>
          <el-pagination background :current-page="listQuery.pageIndex" :page-size="listQuery.pageSize" :layout="layout"
            :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
        </div>

      </div>

    </div>

    <span slot="footer" class="dialog-footer">
      <el-button size="medium" type="primary" icon="el-icon-s-check" @click="save">
        确定
      </el-button>
      <el-button size="medium" icon="el-icon-delete" @click="close">
        取 消
      </el-button>

    </span>
  </el-dialog>
</template>
<script>
import Upload from '@/components/Upload/upload'
import { queryWuziPage } from '@/api/warehousing'
import { getckwzpage } from '@/api/exwarehouse'



let _listQuery = {
  pageIndex: 1,
  pageSize: 5
}
export default {
  name: 'page1AddWuzi',
  components: { Upload },
  data() {
    return {
      listQuery: Object.assign({}, _listQuery),
      show: true,
      listLoading: true,
      layout: 'prev, pager, next',
      total: 0,
      elementLoadingText: '正在加载...',
      selectRows: '',
      ruleForm: {},
      rules: {
        sl: [{ required: true, message: '请输入数量', trigger: 'blur' }],
        ffkf: [{ required: true, message: '请选择库房', trigger: 'blur' }],
      },
      tabheight: 500,
      importShow: false,
      kfList: [
        { value: '库房1', label: '库房1' },
        { value: 2, label: '库房2' },
        { value: 3, label: '库房3' }],
      dialogFormVisible: false,
      wuzizyid: ''
    }
  },
  created() { },
  mounted() {
    // this.ruleForm = Object.assign({}, this.datarow)
    // console.log(this.ruleForm);
    this.getData();
  },
  methods: {
    setSelectRows(val) {

      this.selectRows = val
    },
    async getData() {
      this.listQuery.wuzizyid = this.wuzizyid
      const wzData = await queryWuziPage(this.listQuery)
      // const wzData = await getckwzpage(this.listQuery)
      this.total = wzData.data.total
      this.ruleForm = Object.assign({}, wzData.data)
      this.listLoading = false;
    },
    showEdit(row) {
      this.dialogFormVisible = true
    },
    close() {
      //  this.$refs['form'].resetFields()
      //  this.form = this.$options.data().form
      this.dialogFormVisible = false
      this.resetlist();
    },
    save() {

      if (this.selectRows.length == 0) {
        this.$message({
          message: '请先勾选数据',
          type: 'warning',
        });
        return

      }
      this.$emit('fetch-data', this.selectRows)
      this.close()
    },
    goBack() {
      this.$parent.addshow = false
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          return false
        }
      })
    },

    selectChange(e) { },
    search() {
      this.getData()
    },
    resetlist() {
      this.listQuery = Object.assign({}, _listQuery)
      this.getData()
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.getData()
    },
    handleCurrentChange(val) {
      this.listQuery.pageIndex = val
      this.getData()
    },
  },
}
</script>
<style lang="scss" scoped>
.search-group {
  display: flex;
  flex-flow: row wrap;

  .search-gropu-item {
    padding: 10px 20px;
    width: calc((100% - 20px * 8) / 2);
    display: flex;

    label {
      width: .8rem;
      white-space: nowrap;
      line-height: .32rem;
      margin-right: .1rem;
    }

    .el-select {
      width: 100%;
    }
  }

  .search-gropu-item-time {
    width: 500px !important;
    padding: 10px 20px;
    display: flex;

    label {
      white-space: nowrap;
      line-height: 32px;
      margin-right: 10px;
    }
  }

  .search-button {
    margin-left: auto;
    padding: .10rem .20rem;

    .el-button {
      font-size: .14rem !important;
    }
  }
}

.add-container {

  width: 100%;
  height: 100%;
  z-index: 1000;
  background-color: #f6f8f9;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  .add-top {


    ::v-deep .el-page-header__title {
      font-size: 16px !important;
    }
  }

  .add-main {
    flex: 1;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    overflow: auto;

    .add-main-top {
      padding: .2rem;
      background: #fff;
      border-radius: .05rem;

      .add-main-tital {
        font-size: .18rem;
        border-left: .10rem solid rgb(121, 189, 255);
        padding-left: .10rem;

        p {
          margin: 0;
        }
      }

      .search-gropu-item {
        margin-top: .20rem;
        width: 90%;
        display: flex;
        // label {
        //   white-space: nowrap;
        //   line-height: 32px;
        //   margin-right: 10px;
        // }
      }

      .el-select {
        width: 100%;
      }
    }

    .add-main-list {
      flex: 1;
      background: #fff;
      box-sizing: border-box;

      .list-button-group {
        display: flex;
        flex-direction: row;
        padding: 15px;

        .button-item {
          padding: 0px 10px;
        }

        .button-item:first-child,
        &:last-child {
          padding: 0px 10px 0 0;
        }
      }
    }

    .el-button {
      font-size: .14rem !important;
    }

    ::v-deep {
      .elx-table--header-wrapper {
        background-color: rgb(233, 243, 255);
      }

      .elx-table {
        font-size: 0.14rem !important;
      }

      .elx-body--column {
        height: .48rem !important;
        line-height: .24rem;
      }

      .elx-header--column {
        background-image: none !important;
        height: .48rem !important;
      }

      .el-date-editor.el-input,
      .el-date-editor.el-input--inner {
        width: 100% !important;
      }

      .el-form-item--small.el-form-item {
        margin-bottom: 0px;
        margin-top: 18px;
      }
    }

    .submit-button {
      margin-top: 20px;
      display: flex;
      justify-content: center;
    }
  }
}
</style>